﻿using System;

using OpenQA.Selenium;
using OpenQA.Selenium.Support.UI;

using NUnit.Framework;

namespace mvcForum.Tests.WebUI {

	[TestFixture]
	public class A001_InstallRedirect {
		private static IWebDriver driver;

		#region Initialization and cleanup
		[TestFixtureSetUp]
		public static void TestInitialize() {
			driver = TestHelper.GetDriver();
		}

		[TestFixtureTearDown]
		public static void TestCleanup() {
			if (driver != null) {
				driver.Close();
			}
		}
		#endregion

		[Test]
		public void TestRedirectToInstall() {
			driver.VisitURL("");
			//driver.Navigate().GoToUrl(String.Format("{0}", TestHelper.SiteBaseURL));
			var link = driver.FindElement(By.LinkText("The forum"));
			Assert.IsNotNull(link);
			link.Click();

			WebDriverWait wait = new WebDriverWait(driver, new TimeSpan(0, 0, 5));
			wait.Until(drv => drv.FindElement(By.Id("install")));

			Assert.AreEqual(String.Format("{0}forumadmin/basicinstall", TestConfiguration.SiteBaseURL), driver.Url.ToLower());
			Assert.AreEqual(true, driver.PageSource.Contains("Basic Installation"));

			driver.VisitURL("");
			//driver.Navigate().GoToUrl(String.Format("{0}", TestHelper.SiteBaseURL));
			link = driver.FindElement(By.LinkText("The admin panel"));
			Assert.IsNotNull(link);
			link.Click();

			wait.Until(drv => drv.FindElement(By.Id("Password")));

			Assert.AreEqual(String.Format("{0}forum/account/logon?returnurl=%2fforumadmin", TestConfiguration.SiteBaseURL), driver.Url.ToLower());
			//Assert.AreEqual(true, driver.PageSource.Contains("Please enter your e-mail address and password"));
		}
	}
}